
var Genders = [{ id:'MSSQL', text: 'MSSQL' }, { id: 'MYSQL', text: 'MYSQL'}, { id: 'ORACLE', text: 'ORACLE'}];

mini.parse();

var grid = mini.get("datagrid1");
grid.load({tablename:"dbinfo"});


//////////////////////////////////////////////////////
function  reloaddata() {
    grid.reload();
}
function search() {
    var key = mini.get("key").getValue();

    grid.load({ key: key });
}

function onKeyEnter(e) {
    search();
}

function addRow() {
    var newRow = { cType: "1" };
    grid.addRow(newRow, 0);

    grid.beginEditCell(newRow, "cTyep");
}
function removeRow() {
    var rows = grid.getSelecteds();
    if (rows.length > 0) {

        grid.removeRows(rows, true);
    }
}
function saveData() {
    grid.commitEdit();
    var rowData = grid.getChanges();
    grid.loading("保存中，请稍后......");
    var json = mini.encode({"tablename": "dbinfo","data":rowData});
    $.ajax({
        type:"post",
        url: "../../dbserver/savedbinfo",
        data: {info:json},
        success: function (text) {
            grid.reload();
        },
        error: function (jqXHR, textStatus, errorThrown) {
            mini.alert(jqXHR.responseText);
        }
    });
}
function removeRow() {
    var rows = grid.getSelecteds();
    if (rows.length > 0) {

        grid.removeRows(rows, true);
    }
}

grid.on("celleditenter", function (e) {
    var index = grid.indexOf(e.record);
    if (index == grid.getData().length - 1) {
        var row = {};
        grid.addRow(row);
    }
});

grid.on("beforeload", function (e) {
    if (grid.getChanges().length > 0) {
        if (confirm("有增删改的数据未保存，是否取消本次操作？")) {
            e.cancel = true;
        }
    }
});

